﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;
using CNotebook.Sales;
using CNotebook.Inventory;

namespace NotebookS2
{
    public partial class M_ITEMMASTER : RibbonForm
    {
        public M_ITEMMASTER()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        #region Functions
        bool IsCompleteData()
        {
            if (txtCode.Text.Trim() != "" && txtDescription.Text.Trim() != "")
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        void BindDivision(string sItemGroup)
        {
            ItemManager oManager = new ItemManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable oTable = oManager.GetItemDivision(sItemGroup);
            oManager.Close();
          
            cboDivision.DataSource = oTable;
            cboDivision.ValueMember = "DivisionCode";
            cboDivision.DisplayMember = "DivisionName";

            cboDivision.Refresh();

        }

        void BindItemCategory(string sDivision)
        {
            ItemManager oManager = new ItemManager();
            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable oTable = oManager.GetItemCategory(sDivision);
            oManager.Close();



            cboItemCategory.DataSource = oTable;
            cboItemCategory.ValueMember = "CategoryCode";
            cboItemCategory.DisplayMember = "CategoryName";

            cboItemCategory.Refresh();

        }

        void BindItemClass(string sDivision, string sCategory)
        {
            ItemManager oManager = new ItemManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable oTable = oManager.GetClassification(sDivision, sCategory);
            oManager.Close();

            //oTable = oManager.GetClassification(sDivision, sCategory);

            cboItemClass.DataSource = oTable;
            cboItemClass.ValueMember = "ClssCode";
            cboItemClass.DisplayMember = "ClssName";

            cboItemClass.Refresh();


        }

        //void BindBrand()
        //{
        //    BrandManager oManager = new BrandManager();
        //    DataTable _table = new DataTable();
        //    oManager.ConnectionString = this.ConnectionString;
        //    oManager.Open();
        //    _table = oManager.GetBrands();
        //    oManager.Close();

        //    cboBrand.DisplayMember = "BrandID";
        //    cboBrand.ValueMember = "BrandName";
        //    cboBrand.DataSource = _table;
        //    cboBrand.Refresh();
        //}

        bool IsNumeric(string value_)
        {
            try
            {
                int iChecker;

                iChecker = Convert.ToInt16(value_);

                return true;
            }
            catch
            {
                return false;
            }
        }

        void DisableItems()
        {
            txtCode.ReadOnly = true;
            btnAdd.Text = "Update";
        }

        public void ShowSearch()
        {
            FND_ITEM oFindItemForm = new FND_ITEM();

            oFindItemForm.ConnectionString = this.ConnectionString;
            oFindItemForm.ShowDialog();

            string sItemCode = oFindItemForm.SelectedItemCode;

            if (sItemCode != null)
            {
                ItemManager oManager = new ItemManager();

                BindBOM(sItemCode);
                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();
                DataTable oTable = oManager.GetItemMasterData(sItemCode);
                oManager.Close();

                txtCode.Text = oTable.Rows[0]["ItemCode"].ToString();
                txtDescription.Text = oTable.Rows[0]["Description"].ToString();
                txtBarCode.Text = oTable.Rows[0]["BarCode"].ToString();
                cboItemType.Text = oTable.Rows[0]["ItemType"].ToString();
                cboItemGroup.Text = oTable.Rows[0]["ItemGroup"].ToString();

                BindDivision(cboItemGroup.Text);
                cboDivision.SelectedValue = oTable.Rows[0]["ItemDivision"].ToString();
                cboItemCategory.SelectedValue = oTable.Rows[0]["ItemCategory"].ToString();
                cboItemClass.SelectedValue = oTable.Rows[0]["ItemClass"].ToString();



                txtAdditionalIdentifier.Text = oTable.Rows[0]["ItmIdent"].ToString();
                txtMFRCatalogNo.Text = oTable.Rows[0]["MfrCatalog"].ToString();
                txtPurchasingUOM.Text = oTable.Rows[0]["PurUntMsr"].ToString();
                txtItemPerPurchUnit.Text = oTable.Rows[0]["ItmPerPurUnit"].ToString();
                txtSalesUOM.Text = oTable.Rows[0]["SalUntMsr"].ToString();
                txtItmSalesPerUnt.Text = oTable.Rows[0]["ItmPerSaleUnit"].ToString();
                txtInvntryUOM.Text = oTable.Rows[0]["InvtyUntMsr"].ToString();

                txtSmallestUoM.Text = oTable.Rows[0]["SmallestInvtyUoM"].ToString();


                txtMaxStock.Text = oTable.Rows[0]["MaxStock"].ToString();
                txtMinimumStock.Text = oTable.Rows[0]["MinStock"].ToString();
                if (oTable.Rows[0]["AcctCode"] != DBNull.Value)
                {
                    txtGLAcctCode.Text = oTable.Rows[0]["AcctCode"].ToString();
                }
                else { txtGLAcctCode.Text = ""; }
                if (oTable.Rows[0]["AcctName"] != DBNull.Value) { txtGLName.Text = oTable.Rows[0]["AcctName"].ToString(); }
                else
                {
                    txtGLName.Text = ""; 
                }

                cboBrand.SelectedIndex = -1;

                if (oTable.Rows[0]["Brand"] != DBNull.Value)
                {
                    if (oTable.Rows[0]["Brand"].ToString() != "")
                    {
                        cboBrand.SelectedValue = oTable.Rows[0]["Brand"].ToString();
                    }
                    else
                    {
                        cboBrand.SelectedIndex = -1;
                    }
                }
                else
                {
                    cboBrand.SelectedIndex = -1;
                }

                if (oTable.Rows[0]["ProductCategory"] != DBNull.Value)
                {
                    cboProductCategory.SelectedValue = oTable.Rows[0]["ProductCategory"].ToString();
                }
                else
                {
                    cboProductCategory.SelectedIndex = -1;
                }

                if (oTable.Rows[0]["Product"] != DBNull.Value)
                {
                    cboProduct.SelectedValue = oTable.Rows[0]["Product"].ToString();
                }
                else
                {
                    cboProduct.SelectedIndex = -1;
                }

                if (oTable.Rows[0]["Variant"] != DBNull.Value)
                {
                    cboVariant.SelectedValue = oTable.Rows[0]["Variant"].ToString();
                }
                else
                {
                    cboVariant.SelectedIndex = -1;
                }

                if (oTable.Rows[0]["ProductSize"] != DBNull.Value)
                {
                    if (oTable.Rows[0]["ProductSize"].ToString() != "")
                    {
                        cboSize.SelectedValue = oTable.Rows[0]["ProductSize"].ToString();
                    }
                    else
                    {

                        cboSize.SelectedIndex = -1;
                    }
                }
                else
                {
                    cboSize.SelectedIndex = -1;
                }
                
                chkProduction.Checked = (bool)oTable.Rows[0]["IsProduction"];
                chkForQuarantine.Checked = (bool)oTable.Rows[0]["IsForQuarantine"];
                
                chkIsPurchasedItem.Checked = (bool)oTable.Rows[0]["IsPurchasedItem"];
                chkIsSalesItem.Checked = (bool)oTable.Rows[0]["IsSalesItem"];
                chkIsInventoryItem.Checked = (bool)oTable.Rows[0]["IsInventoryItem"];
                chkIsFixedAsset.Checked = (bool)oTable.Rows[0]["IsFixedAsset"];

                if (((bool)oTable.Rows[0]["IsActive"]) == true)
                {
                    chkActive.Checked = true;
                    chkInActive.Checked = false;
                }
                else
                {
                    chkActive.Checked = false;
                    chkInActive.Checked = true;
                }

                

                DisableItems();

                btnAdd.Text = "Update";
            }

            this.Refresh();


        }

        void BindBrand(string _ItemGroup)
        {
            BrandManager oManager = new BrandManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable _table = oManager.GetBrands(_ItemGroup);
            oManager.Close();

            cboBrand.DisplayMember = "BrandName";
            cboBrand.ValueMember = "BrandID";
            cboBrand.DataSource = _table;
            cboBrand.Refresh();

            

        }

        void BindCategory(string _BrandID)
        {
            BrandCategoryManager oManager = new BrandCategoryManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable _table = oManager.GetCategoryByBrandID(_BrandID);
            oManager.Close();

            cboProductCategory.DisplayMember = "CatgryName";
            cboProductCategory.ValueMember = "CatgryCode";
            cboProductCategory.DataSource = _table;
            cboProductCategory.Refresh();
        }

        void BindProduct(string _BrandID, string _CatgryCode)
        {
            ProductManager oManager = new ProductManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable _table = oManager.GetProducts(_BrandID, _CatgryCode);

            oManager.Close();

            cboProduct.DisplayMember = "ProductName";
            cboProduct.ValueMember = "ProdCode";
            cboProduct.DataSource = _table;
            cboProduct.Refresh();
        }

        void BindVariant(string _BrandID, string _CatgryCode, string _ProdCode)
        {

            ProductVariantManager oManager = new ProductVariantManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable _table = oManager.GetVariants(_BrandID, _CatgryCode, _ProdCode);

            oManager.Close();

            cboVariant.DisplayMember = "VrntName";
            cboVariant.ValueMember = "VrntCode";
            cboVariant.DataSource = _table;
            cboVariant.Refresh();
        }

        void BindSize(string _BrandID, string _CatgryCode, string _ProdCode, string _Variant)
        {
            ProductSizeManager oManager = new ProductSizeManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable _table = oManager.GetSizes(_BrandID, _CatgryCode, _ProdCode, _Variant);

            oManager.Close();

            cboSize.DisplayMember = "SizeWithMsr";
            cboSize.ValueMember = "Size";
            cboSize.DataSource = _table;
            cboSize.Refresh();
        }

        void BindBOM(string sItemCode)
        {
            KitManager oManager = new KitManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable _table = oManager.GetBOMByItemCode(sItemCode);

            oManager.Close();

            cboBOM.DataSource = _table;
            cboBOM.DisplayMember = "BOMName";
            cboBOM.ValueMember = "BOMCode";
            cboBOM.Refresh();
        }

        #endregion

        #region UI Events
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void M_ItemMaster_Load(object sender, EventArgs e)
        {
            xtraTabPage5.PageVisible = false;
            cboItemGroup.SelectedIndex = 0;
            cboItemType.SelectedIndex = 0;
            BindDivision(cboItemGroup.Text);

            BindBrand(cboItemGroup.Text);
            try{
            BindCategory(cboBrand.SelectedValue.ToString());
            }catch{}

            try
            {
                BindProduct(cboBrand.SelectedValue.ToString(), cboProductCategory.SelectedValue.ToString());
            }
            catch { }
            try
            {
                BindVariant(cboBrand.SelectedValue.ToString(), cboProductCategory.SelectedValue.ToString(), cboProduct.SelectedValue.ToString());
            }
            catch { }

            try
            {
                BindSize(cboBrand.SelectedValue.ToString(), cboProductCategory.SelectedValue.ToString(), cboProduct.SelectedValue.ToString(), cboVariant.SelectedValue.ToString());
            }
            catch { }

        }

        private void cboDivision_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string sDivision = "";
                string sItemCategory = "";

                if (cboDivision.SelectedValue != null)
                {
                    sDivision = cboDivision.SelectedValue.ToString();
                }
                if (cboItemCategory.SelectedValue != null)
                {
                    sItemCategory = cboItemCategory.SelectedValue.ToString();
                }
                BindItemCategory(sDivision);
                BindItemClass(sDivision, sItemCategory);
            }
            catch
            {
            }
        }

        private void cboItemCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string sDivision = "";
                string sItemCategory = "";

                if (cboDivision.SelectedValue != null)
                {
                    sDivision = cboDivision.SelectedValue.ToString();
                }
                if (cboItemCategory.SelectedValue != null)
                {
                    sItemCategory = cboItemCategory.SelectedValue.ToString();
                }
                BindItemClass(sDivision, sItemCategory);
            }
            catch
            {
            }
        }

        private void cboItemGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {

                BindDivision(cboItemGroup.Text);

                string sDivision = "";
                string sItemCategory = "";

                BindBrand(cboItemGroup.Text);

                cboBrand_SelectedIndexChanged(sender, e);
                if (cboDivision.SelectedValue != null)
                {
                    sDivision = cboDivision.SelectedValue.ToString();
                }
                if (cboItemCategory.SelectedValue != null)
                {
                    sItemCategory = cboItemCategory.SelectedValue.ToString();
                }
                BindItemCategory(sDivision);
                BindItemClass(sDivision, sItemCategory);
            }
            catch
            {
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            ItemUnit oItemUnit = new ItemUnit();
            ItemManager oManager = new ItemManager();


            try
            {
                int iPrice = 0;
                if (btnAdd.Text == "&Add")
                {
                    if (IsCompleteData() == true)
                    {
                        if (IsNumeric(iPrice.ToString()) == true)
                        {
                            oItemUnit.ItemCode = txtCode.Text;
                            oItemUnit.Description = txtDescription.Text;
                            oItemUnit.BarCode = txtBarCode.Text;


                            oItemUnit.UnitPrice = "0";
                            oItemUnit.ItemType = cboItemType.Text;
                            oItemUnit.ItemGroup = cboItemGroup.Text;

                            string sItemDivision = "";
                            string sItemCategory = "";
                            string sItemClass = "";

                            if (cboDivision.SelectedValue != null) { sItemDivision = cboDivision.SelectedValue.ToString(); }
                            if (cboItemCategory.SelectedValue != null) { sItemCategory = cboItemCategory.SelectedValue.ToString(); }
                            if (cboItemClass.SelectedValue != null) { sItemClass = cboItemClass.SelectedValue.ToString(); }

                            oItemUnit.ItemDivision = sItemDivision;
                            oItemUnit.ItemCategory = sItemCategory;
                            oItemUnit.ItemClass = sItemClass;


                            oItemUnit.AccountCode = txtGLAcctCode.Text;
                            oItemUnit.AccountName = txtGLName.Text;

                            //@Manufctr, @ItmIdent, @MfrCatalog, @PurUntMsr, @ItmPerPurUnit, @SalUntMsr, @ItmPerSaleUnit, @InvtyUntMsr

                            oItemUnit.Manufacturer = txtMFR.Text;
                            oItemUnit.AdditionalIdentifier = txtAdditionalIdentifier.Text;
                            oItemUnit.ManufacturingCatalogNo = txtMFRCatalogNo.Text;
                            oItemUnit.PurchasingUOM = txtPurchasingUOM.Text;
                            oItemUnit.ItemPerPurchaseUnit = Convert.ToInt16(txtItemPerPurchUnit.Text);
                            oItemUnit.SalesUOM = txtSalesUOM.Text;
                            oItemUnit.ItemPerSalesUnit = Convert.ToInt16(txtItmSalesPerUnt.Text);
                            oItemUnit.InvntyUOM = txtInvntryUOM.Text;
                            oItemUnit.SmallestInvntyUOM = txtSmallestUoM.Text;

                            if (cboBrand.SelectedValue != null)
                            {
                                oItemUnit.Brand = cboBrand.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.Brand = "";
                            }
                            if (cboProductCategory.SelectedValue != null)
                            {
                                oItemUnit.ProductCategory = cboProductCategory.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.ProductCategory = "";
                            }
                            if (cboProduct.SelectedValue != null)
                            {
                                oItemUnit.Product = cboProduct.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.Product = "";
                            }
                            if (cboVariant.SelectedValue != null)
                            {
                                oItemUnit.Variant = cboVariant.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.Variant = "";
                            }
                            if (cboSize.SelectedValue != null)
                            {
                                oItemUnit.Size = cboSize.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.Size = "";
                            }
                            oItemUnit.ProductUnit = "";

                            oItemUnit.IsProduction = chkProduction.Checked;
                            oItemUnit.IsForQuarantine = chkForQuarantine.Checked;
                            oItemUnit.IsInventoryItem = chkIsInventoryItem.Checked;
                            oItemUnit.IsPurchasedItem = chkIsPurchasedItem.Checked;
                            oItemUnit.IsSalesItem = chkIsSalesItem.Checked;
                            oItemUnit.IsFixedAsset = chkIsFixedAsset.Checked;

                            oItemUnit.MaxStock = Convert.ToDouble(txtMaxStock.Text);
                            oItemUnit.MinStock = Convert.ToDouble(txtMinimumStock.Text);
                            oItemUnit.IsActive = chkActive.Checked;
                            if (cboBOM.SelectedIndex != -1)
                            {
                                oItemUnit.BOMCode = cboBOM.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.BOMCode = "";
                            }


                            oManager.ConnectionString = this.ConnectionString;
                            oManager.Open();
                            oManager.AddItem(oItemUnit);
                            oManager.Close();

                            DisableItems();

                            MessageBox.Show("Item was successfully added!!!", "Item Master", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    if (IsCompleteData() == true)
                    {
                        if (IsNumeric(iPrice.ToString()) == true)
                        {
                            oItemUnit.ItemCode = txtCode.Text;
                            oItemUnit.Description = txtDescription.Text;
                            oItemUnit.BarCode = txtBarCode.Text;


                            oItemUnit.UnitPrice = "0";
                            oItemUnit.ItemType = cboItemType.Text;
                            oItemUnit.ItemGroup = cboItemGroup.Text;

                            string sItemDivision = "";
                            string sItemCategory = "";
                            string sItemClass = "";

                            if (cboDivision.SelectedValue != null) { sItemDivision = cboDivision.SelectedValue.ToString(); }
                            if (cboItemCategory.SelectedValue != null) { sItemCategory = cboItemCategory.SelectedValue.ToString(); }
                            if (cboItemClass.SelectedValue != null) { sItemClass = cboItemClass.SelectedValue.ToString(); }

                            oItemUnit.ItemDivision = sItemDivision;
                            oItemUnit.ItemCategory = sItemCategory;
                            oItemUnit.ItemClass = sItemClass;


                            //@Manufctr, @ItmIdent, @MfrCatalog, @PurUntMsr, @ItmPerPurUnit, @SalUntMsr, @ItmPerSaleUnit, @InvtyUntMsr

                            oItemUnit.Manufacturer = txtMFR.Text;
                            oItemUnit.AdditionalIdentifier = txtAdditionalIdentifier.Text;
                            oItemUnit.ManufacturingCatalogNo = txtMFRCatalogNo.Text;
                            oItemUnit.PurchasingUOM = txtPurchasingUOM.Text;
                            oItemUnit.ItemPerPurchaseUnit = Convert.ToInt16(txtItemPerPurchUnit.Text);
                            oItemUnit.SalesUOM = txtSalesUOM.Text;
                            oItemUnit.ItemPerSalesUnit = Convert.ToInt16(txtItmSalesPerUnt.Text);
                            oItemUnit.InvntyUOM = txtInvntryUOM.Text;
                            oItemUnit.SmallestInvntyUOM = txtSmallestUoM.Text;

                            if (cboBrand.SelectedValue != null)
                            {
                                oItemUnit.Brand = cboBrand.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.Brand = "";
                            }
                            if (cboProductCategory.SelectedValue != null)
                            {
                                oItemUnit.ProductCategory = cboProductCategory.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.ProductCategory = "";
                            }
                            if (cboProduct.SelectedValue != null)
                            {
                                oItemUnit.Product = cboProduct.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.Product = "";
                            }
                            if (cboVariant.SelectedValue != null)
                            {
                                oItemUnit.Variant = cboVariant.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.Variant = "";
                            }
                            if (cboSize.SelectedValue != null)
                            {
                                oItemUnit.Size = cboSize.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.Size = "";
                            }
                            oItemUnit.ProductUnit = "";

                            oItemUnit.AccountCode = txtGLAcctCode.Text;
                            oItemUnit.AccountName = txtGLName.Text;

                            oItemUnit.IsProduction = chkProduction.Checked;
                            oItemUnit.IsForQuarantine = chkForQuarantine.Checked;
                            oItemUnit.IsInventoryItem = chkIsInventoryItem.Checked;
                            oItemUnit.IsPurchasedItem = chkIsPurchasedItem.Checked;
                            oItemUnit.IsSalesItem = chkIsSalesItem.Checked;
                            oItemUnit.IsFixedAsset = chkIsFixedAsset.Checked;
                            oItemUnit.MaxStock = Convert.ToDouble(txtMaxStock.Text);
                            oItemUnit.MinStock = Convert.ToDouble(txtMinimumStock.Text);
                            oItemUnit.IsActive = chkActive.Checked;
                            if (cboBOM.SelectedIndex != -1)
                            {
                                oItemUnit.BOMCode = cboBOM.SelectedValue.ToString();
                            }
                            else
                            {
                                oItemUnit.BOMCode = "";
                            }

                            oManager.ConnectionString = this.ConnectionString;
                            oManager.Open();
                            oManager.UpdateItem(oItemUnit);
                            oManager.Close();
                            DisableItems();
                            MessageBox.Show("Item was successfully updated!!!", "Item Master", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }

            }
            catch
            {
            }


        }

        #endregion

        private void txtBarCode_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void cboBrand_SelectedIndexChanged(object sender, EventArgs e)
        {
            string _Brand = "";
            string _ProductCategory = "";
            string _Product = "";
            string _Variant = "";
            try
            {
                _Brand = cboBrand.SelectedValue.ToString();
            }
            catch { }

            BindCategory(_Brand);

            try
            {
                _ProductCategory = cboProductCategory.SelectedValue.ToString();
            }
            catch { }

            BindProduct(_Brand, _ProductCategory);
            try
            {
                _Product = cboProduct.SelectedValue.ToString();
            }
            catch { }

            BindVariant(_Brand, _ProductCategory, _Product);
            try
            {
                _Variant = cboVariant.SelectedValue.ToString();
            }
            catch { }
            BindSize(_Brand, _ProductCategory, _Product, _Variant);
        }
        
        private void cboProductCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            string _Brand = "";
            string _ProductCategory = "";
            string _Product = "";
            string _Variant = "";
            try
            {
                _Brand = cboBrand.SelectedValue.ToString();
            }
            catch { }
            //BindCategory(_Brand);
            try
            {
                _ProductCategory = cboProductCategory.SelectedValue.ToString();
            }
            catch { }

            BindProduct(_Brand, _ProductCategory);
            try
            {
                _Product = cboProduct.SelectedValue.ToString();
            }
            catch { }

            BindVariant(_Brand, _ProductCategory, _Product);
            try
            {
                _Variant = cboVariant.SelectedValue.ToString();
            }
            catch { }
            
            BindSize(_Brand, _ProductCategory, _Product, _Variant);
        }
        
        private void cboProduct_SelectedIndexChanged(object sender, EventArgs e)
        {

            string _Brand = "";
            string _ProductCategory = "";
            string _Product = "";
            string _Variant = "";
            try
            {
                _Brand = cboBrand.SelectedValue.ToString();
            }
            catch { }
            try
            {
                _ProductCategory = cboProductCategory.SelectedValue.ToString();
            }
            catch { }

            try
            {
                _Product = cboProduct.SelectedValue.ToString();
            }
            catch { }
            BindVariant(_Brand, _ProductCategory, _Product);
            try
            {
                _Variant = cboVariant.SelectedValue.ToString();
            }
            catch { }
            //BindCategory(_Brand);
            //BindProduct(_Brand, _ProductCategory);
            
            BindSize(_Brand, _ProductCategory, _Product, _Variant);
        }

        private void cboVariant_SelectedIndexChanged(object sender, EventArgs e)
        {
            string _Brand = "";
            string _ProductCategory = "";
            string _Product = "";
            string _Variant = "";
            try
            {
                _Brand = cboBrand.SelectedValue.ToString();
            }
            catch { }
            try
            {
                _ProductCategory = cboProductCategory.SelectedValue.ToString();
            }
            catch { }

            try
            {
                _Product = cboProduct.SelectedValue.ToString();
            }
            catch { }
            try
            {
                _Variant = cboVariant.SelectedValue.ToString();
            }
            catch { }
            //BindCategory(_Brand);
            //BindProduct(_Brand, _ProductCategory);
            //BindVariant(_Brand, _ProductCategory, _Product);
            BindSize(_Brand, _ProductCategory, _Product, _Variant);
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void txtGLAcctCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            FND_GLACCOUNT oForm = new FND_GLACCOUNT();

            oForm.ConnectionString = this.ConnectionString;

            oForm.ShowDialog();

            txtGLAcctCode.Text =  oForm.SelectedGLAcctCode;
            txtGLName.Text =  oForm.SelectedGLAcctName;

        }

        private void label14_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void cboItemType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboItemType.Text == "Package")
            {
                xtraTabPage5.PageVisible = true;
            }
            else
            {
                xtraTabPage5.PageVisible = false;
            }
        }

        private void M_ITEMMASTER_Resize(object sender, EventArgs e)
        {
            groupControl1.Width = this.Width - 20;
            xtraTabControl1.Width = this.Width - 20;
            groupControl2.Width = this.Width / 2 - 20;
            groupControl3.Left = groupControl2.Width + 20;
            groupControl3.Width = this.Width / 2 - 12;
        }
    }
}
